/**
 * Licensee: Carla Painemilla
 * License Type: Evaluation
 */
package ormsamples;

import org.orm.*;
public class CreateDiagnosticoData {
	public void createTestData() throws PersistentException {
		// Insert sample data
		java.sql.Connection conn = orm.DiagnosticoPersistentManager.instance().getSession().connection();
		try {
			java.sql.Statement statement = conn.createStatement();
			statement.executeUpdate("insert into Subsector(sub_id, sub_descrip, Cursocurso_id) values (1, '', null)");
			statement.executeUpdate("insert into Anotacion(anotacion_id, anotacion_fecha, anotacion_descripcion, Tipotianotacion_id, Subsectorsub_id, Anotadoranot_id, Alumnoalu_id) values (1, null, null, null, null, null, null)");
			conn.commit();
		}
		catch (Exception e) {
			try {
				conn.rollback();
			}
			catch (java.sql.SQLException e1) {
				e.printStackTrace();
			}
			e.printStackTrace();
		}
		
		PersistentTransaction t = orm.DiagnosticoPersistentManager.instance().getSession().beginTransaction();
		try {
			orm.DAOFactory lDAOFactory = orm.DAOFactory.getDAOFactory();
			orm.dao.CursoDAO oRMCursoDAO = lDAOFactory.getCursoDAO();
			orm.Curso oRMCurso = oRMCursoDAO.createCurso();
			// TODO Initialize the properties of the persistent object here, the following properties must be initialized before saving : subsector, alumno
			oRMCursoDAO.save(oRMCurso);
			orm.dao.AlumnoDAO oRMAlumnoDAO = lDAOFactory.getAlumnoDAO();
			orm.Alumno oRMAlumno = oRMAlumnoDAO.createAlumno();
			// TODO Initialize the properties of the persistent object here, the following properties must be initialized before saving : anotacion, cursocurso, alu_dv, alu_rut, alu_nombre
			oRMAlumnoDAO.save(oRMAlumno);
			orm.dao.AnotacionDAO oRMAnotacionDAO = lDAOFactory.getAnotacionDAO();
			orm.Anotacion oRMAnotacion = oRMAnotacionDAO.createAnotacion();
			// TODO Initialize the properties of the persistent object here, the following properties must be initialized before saving : alumnoalu, anotadoranot, subsectorsub, tipotianotacion, anotacion_descripcion, anotacion_fecha
			oRMAnotacionDAO.save(oRMAnotacion);
			orm.dao.AnotadorDAO oRMAnotadorDAO = lDAOFactory.getAnotadorDAO();
			orm.Anotador oRMAnotador = oRMAnotadorDAO.createAnotador();
			// TODO Initialize the properties of the persistent object here, the following properties must be initialized before saving : anotacion, anot_nombre
			oRMAnotadorDAO.save(oRMAnotador);
			orm.dao.TipoDAO oRMTipoDAO = lDAOFactory.getTipoDAO();
			orm.Tipo oRMTipo = oRMTipoDAO.createTipo();
			// TODO Initialize the properties of the persistent object here, the following properties must be initialized before saving : anotacion, tianotacion_descrip
			oRMTipoDAO.save(oRMTipo);
			orm.dao.SubsectorDAO oRMSubsectorDAO = lDAOFactory.getSubsectorDAO();
			orm.Subsector oRMSubsector = oRMSubsectorDAO.createSubsector();
			// TODO Initialize the properties of the persistent object here, the following properties must be initialized before saving : anotacion, cursocurso, sub_descrip
			oRMSubsectorDAO.save(oRMSubsector);
			t.commit();
		}
		catch (Exception e) {
			t.rollback();
		}
		
	}
	
	public static void main(String[] args) {
		try {
			CreateDiagnosticoData createDiagnosticoData = new CreateDiagnosticoData();
			try {
				createDiagnosticoData.createTestData();
			}
			finally {
				orm.DiagnosticoPersistentManager.instance().disposePersistentManager();
			}
		}
		catch (Exception e) {
			e.printStackTrace();
		}
	}
}
